#pragma once

#include "SqlProtocol.hpp"
#include "CritSection.h"
#include "SqlClient.h"


class RequestWorker
{
	static const int WAIT_REQUEST_PAUSE = 1*1000;

public:
	RequestWorker(bool destroySelfAfterFirstRequest);
	~RequestWorker();

	void pushRequest(const SqlRequest &request);

protected:
	void work();
	void process(const SqlRequest &request);
	const SqlRequest & currentRequest() const;
	void nextRequest();

private:
	static DWORD WINAPI work_entry(LPVOID lpParameter);

	std::vector<SqlRequest*> requests;
	CritSectionLocker requestsLocker;
	SqlClient client;
	bool destroySelf;
	HANDLE workThread;
};
